package ws.jonas.common.model;

import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

/**
 * Immutable.
 */
public class ProductQuantity implements Iterable<Map.Entry<Store, Integer>> {
	private final Product product;
	private final Map<Store, Integer> quantities;

	public ProductQuantity(Product product, Map<Store, Integer> quantities) {
		if (product == null) {
			throw new NullPointerException("product");
		}
		if (quantities == null) {
			throw new NullPointerException("quantities");
		}
		this.product = product;
		this.quantities = Collections.unmodifiableMap(quantities);
	}

	public Product getProduct() {
		return product;
	}

	public Map<Store, Integer> getQuantities() {
		return quantities;
	}

	@Override
	public String toString() {
		return "ProductQuantityWrapper [product=" + product + ", quantities=" + quantities + "]";
	}

	@Override
	public Iterator<Entry<Store, Integer>> iterator() {
		return quantities.entrySet().iterator();
	}
}
